/*
 * @Author: xmily
 * @Date: 2021-11-09 22:03:39
 * @LastEditors: xmily
 * @LastEditTime: 2023-05-09 22:47:31
 * @FilePath: \glxxapi\models\AfterClassService\application.js
 * @Description:
 *
 * Copyright (c) 2022 by xmily/mxthink.com.cn, All Rights Reserved.
 */
//课后服务申请记录表
var mongoose = require("../../cfg/dbconfig.js");

var applicationSchema = new mongoose.Schema(
  {
    month: String,
    baselesson: Boolean,
    interestlesson: Array,
    applicationwrite: String,
    safewrite: String,
    classno: String,
    stuname: String,
    stuid: String,
    term: String,
    schoolname: String,
    status: String,
    selected: String,
    trainingTeam:String,
    addmode: String,
    mem:[String],
  },
  { collection: "aftclsvr_application" }
);

applicationSchema.statics.Save = async function (doc) {
  let obj = new this(doc);
  if (doc._id) {
    obj.isNew = false;
  }
  let res = await obj.save();
  return res;
};

applicationSchema.statics.Update = async function (doc) {
  let id = doc._id;
  delete doc._id;
  let result = await this.updateOne({ _id: id }, doc).exec();
  return result;
};

applicationSchema.statics.UpdateByQuery = async function (
  query,
  update,
  options
) {
  // if(query._id){
  //   query._id=mongoose.Types.ObjectId(query._id)
  // }
  options = options || { upsert: false, multi: false };
  let result = await this.update(query, update, options).exec();
  return result;
};

applicationSchema.statics.GetOneByQuery = async function (query) {
  let result = await this.findOne(query).exec();
  return result;
};

//删除记录
applicationSchema.statics.Del = async function (query) {
  let result = await this.deleteOne(query).exec();
  return result;
};

applicationSchema.statics.GetByQuery = async function (query, field, sort) {
  sort = sort || { _id: 1 };
  field = field || {};
  let result = await this.find(query, field).sort(sort).exec();
  return result;
};

applicationSchema.statics.myAggregate = async function (Pipeline) {
  let result = await this.aggregate(Pipeline).exec();
  return result;
};

module.exports = mongoose.model("aftclsvr_application", applicationSchema);
